package com.Algorithm.NIUKE.N202204;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2022/04/11/10:53
 * @Description:
 * @Target:
 */
public class 反转链表 {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] ss1 = in.readLine().split(" ");

        ListNode head = new ListNode();
        head.val = ss1[0];

        ListNode tempNode = new ListNode();  // 中转
        tempNode = head;
        for (int i = 1; i < ss1.length; i++) {
            ListNode newNode = new ListNode();
            newNode.val = ss1[i];
            tempNode.nextNode = newNode;
            tempNode = newNode;
        }


        ListNode listNode = ReverseList(head);
        while (listNode!=null){
            System.out.print(listNode.val+" ");
            listNode = listNode.nextNode;
        }

    }



    static ListNode ReverseList(ListNode head) {
        ListNode tempHead = new ListNode();
        tempHead.val = "head";
        while (head!=null){
            ListNode newNode = new ListNode();
            newNode.val = head.val;
            head = head.nextNode;
            newNode.nextNode = tempHead.nextNode;
            tempHead.nextNode = newNode;
        }

        return tempHead.nextNode;
    }

    static class ListNode{
        private String val;
        private ListNode nextNode;

        public ListNode() {
        }

        public ListNode(String val, ListNode nextNode) {
            val = val;
            this.nextNode = nextNode;
        }
    }
}
